home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / smsrc / sm / launchprogram.pas < prev    next >
Pascal/Delphi Source File  |  1995-07-11  |  2KB  |  65 lines

  1. Function StartCLIProgram;
  2.  
  3. VAR
  4.     newcd   : BPTR;     { Lock for program's current directory }
  5.     oldcd   : BPTR;     { pointer to old current directory }
  6.     t       : Array[0..6] of tTagItem; { tags for SystemTags() }
  7.     cmd,dir : String;
  8.     out     : String;
  9.     outfile : BPTR;
  10.     rc,OK   : Boolean;
  11.  
  12. Begin
  13.     rc := False;
  14.     cmd := node^.LSK_Cmd[1] + #0; { null terminate }
  15.     dir := node^.LSK_Cmd[0] + #0; { null terminate }
  16.     newcd := Lock(@dir[1] ,SHARED_LOCK);
  17.     if (newcd <> 0) and (node^.LSK_Cmd[1] <> '') then begin
  18.  
  19.         { Go to program's current directory }
  20.         oldcd := CurrentDir(newcd);
  21.  
  22.         { open IO file }
  23.         if node^.LSK_Output = '' then Out := 'NIL:'#0
  24.         else out := node^.LSK_Output+#0;
  25.          
  26.         outfile := Open(@out[1], MODE_OLDFILE);
  27.         
  28.         { Start program }
  29.                 
  30.         t[0].ti_Tag  := SYS_Asynch;
  31.         t[0].ti_Data := Ord(node^.LSK_ASynch);
  32.         t[1].ti_Tag  := SYS_Input;
  33.         t[1].ti_Data := outfile;
  34.         t[2].ti_Tag  := NP_StackSize;
  35.         t[2].ti_Data := node^.LSK_Stack;
  36.         t[3].ti_Tag  := NP_Priority;
  37.         t[3].ti_Data := node^.LSK_Priority;
  38.         t[4].ti_Tag  := SYS_Output;
  39.         t[4].ti_Data := 0;
  40.         t[5].ti_Tag  := SYS_UserShell;
  41.         t[5].ti_Data := True_;
  42.         t[6].ti_Tag  := TAG_END;
  43.                 
  44.         if SystemTagList(@cmd[1],@t) = 0 then
  45.            rc := TRUE; { Program started! }
  46.            
  47.       if NOT rc then begin
  48.           ok := Close_(outfile);
  49.           outfile := 0;
  50.       end;
  51.       
  52.       if NOT node^.LSK_ASynch then begin
  53.           if outfile <> 0 then
  54.               ok := Close_(outfile);
  55.       end;
  56.           
  57.       { Go back to old current directory }
  58.       newcd := CurrentDir(oldcd);
  59.     End;
  60.     UnLock(newcd);
  61.     if node^.LSK_Cmd[1] = '' then 
  62.         rc := True;
  63.     StartCLIProgram := rc;
  64. End;
  65.